package com.ktjy.ktmall.dao.impl;

import com.ktjy.ktmall.dao.BannerItemDao;
import com.ktjy.ktmall.dao.BaseDao;
import com.ktjy.ktmall.entity.BannerItem;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;

/**
 * 轮播图模块DAO接口实现类
 * @version v1.0
 * @Author 郴州科泰
 * @Create 2024-07-17 - 16:57
 */
public class BannerItemDaoImpl extends BaseDao implements BannerItemDao {
    /**
     * 根据跳转类型获取轮播图数据列表数据
     * @param type 跳转类型
     * @return 获取到的轮播图数据列表数据
     */
    @Override
    public List<BannerItem> findByType(int type) {
        List<BannerItem> list = new ArrayList<>();
        String sql = "select * from t_banner where `enabled` = 0 and `type` = ?";
        rs = super.executeQuery(sql, type);
        try {
            while (rs.next()) {
                BannerItem b = new BannerItem(rs.getInt(1),rs.getString(2), rs.getString(3), rs.getInt(4),rs.getInt(5),rs.getString(6), rs.getString(7));
                list.add(b);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            super.closeAll(rs, pstmt, conn);
        }
        return list;
    }

    /**
     * 根据品牌id查询品牌详情信息
     * @param id 品牌id
     * @return 返回查询到的品牌详情信息
     */
    @Override
    public BannerItem findById(int id) {
        BannerItem b = null;
        String sql = "select * from t_banner where `enabled` = 0 and `id` = ?";
        rs = super.executeQuery(sql, id);
        try {
            while (rs.next()) {
                b = new BannerItem(rs.getInt(1),rs.getString(2), rs.getString(3), rs.getInt(4),rs.getInt(5),rs.getString(6), rs.getString(7));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            super.closeAll(rs, pstmt, conn);
        }
        return b;
    }

}
